<?php

class Page_Be_LiveSearch extends Page {

	function __construct() {
		parent::__construct();
	}

	public function defaultAction() {
		$searchTerm = post('term');
		$users = Db_Accounts_Users::search(array(
			'u_login' => $searchTerm,
			'u_email' => $searchTerm,
			'u_fullname' => $searchTerm,
			'u_skype' => $searchTerm
		));
		$jsonUsers = array();
		if ($users) {
			foreach ($users as $user) {
				$jsonUsers[] = array(
					'href' => '/accounts/users?action=addEdit&id=' . $user->id,
					'text' => $user->u_fullname
				);
			}
		}
		return array(
			'type' => 'json',
			'content' => $jsonUsers
		);
	}

}
